package com.yqRecite.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yqRecite.entity.Images;
import com.yqRecite.mapper.ImagesMapper;
import com.yqRecite.service.ImagesService;
import com.yqRecite.util.result.Result;
import com.yqRecite.util.result.ResultUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ImagesServiceImpl implements ImagesService {
    @Resource
    private ImagesMapper imagesMapper;

    @Override
    public Result addOneImage(Images image) {
        int res = imagesMapper.insert(image);
        if (res == 1){
            System.out.println("图片上传成功, user==>" + image);
            return ResultUtil.ok(image);
        }else {
            return ResultUtil.error("增加image出现异常", image);
        }
    }

    @Override
    public Result getAllImagesList() {
        List<Images> imagesList = imagesMapper.selectList(new QueryWrapper<>());
        return ResultUtil.ok(imagesList);
    }

    @Override
    public Result deleteImage(int id) {
        int res = imagesMapper.deleteById(id);
        if (res == 1){
            return ResultUtil.ok(id);
        }else {
            return ResultUtil.error("删除image出现异常", id);
        }
    }
}
